package com.eastfair.pay.service.impl;

//import com.baomidou.dynamic.datasource.annotation.DS;
import com.eastfair.core.base.R;
import com.eastfair.pay.service.DictService;
import com.eastfair.projectcore.api.DictionaryFeign;
import com.eastfair.projectcore.entity.Dictionary;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 字典实现类
 * </p>
 *
 * @author fwl
 * @date 2023-03-06
 */
@Slf4j
@Service
//@DS("#thread.tenant")
public class DictServiceImpl  implements DictService {

    @Resource
    private DictionaryFeign dictionaryFeign;

    @Override
    public Map<String, String> getDictByType(String type) {
        //发票类型字典
        R<List<Dictionary>> result = dictionaryFeign.queryDict(type);
        Map<String, String> dictMap = new HashMap<>();
        if (result != null && result.getIsSuccess()) {
            List<Dictionary> dictionaryList = result.getData();
            if (dictionaryList != null && !dictionaryList.isEmpty()) {
                for (Dictionary dictionary : dictionaryList) {
                    dictMap.put(dictionary.getCode(), dictionary.getName());
                }
            }
        }
        return dictMap;
    }
}
